from utils.profile import Profile
from utils.log import Log
from utils.generator import Generator


class QS(Log):
    # is_queue: True queue
    # is_queue: False stack
    def __init__(self, is_queue=True, val=[]):
        super(QS, self).__init__()
        self.c = val
        self.is_queue = is_queue

    # @Profile(log=True)
    def push(self, val):
        self.c.append(val)

    def pop(self, is_queue=None):
        iq = self.is_queue if is_queue is None else is_queue
        if iq:
            return self.c.pop(0)
        else:
            return self.c.pop()

    def is_empty(self):
        return len(self.c) == 0

    def __len__(self):
        return len(self.c)


if __name__ == '__main__':
    g = Generator()
    q = QS()
    q.push(g.single_val())
    q.push(g.single_val())
    print(len(q))
    print(q.pop())
    print(q.pop())
    print(len(q))

    Profile().print_and_reset()

    s = QS(is_queue=False)
    g = Generator()
    s.push(g.single_val())
    s.push(g.single_val())
    print(len(s))
    print(s.pop())
    print(s.pop())
    print(len(s))
